home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4744 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: hermes.louisville.edu!starbase!gclind01
  2. From: gclind01@starbase.spd.louisville.edu (George C. Lindauer)
  3. Newsgroups: comp.os.msdos.programmer,comp.lang.c
  4. Subject: Re: Pointer Stew...
  5. Date: 6 Feb 1996 20:00:05 GMT
  6. Organization: University of Louisville, Louisville KY USA
  7. Message-ID: <4f8c05$79m@hermes.louisville.edu>
  8. References: <svsFxc9nXUNB083yn@mbnet.mb.ca>
  9. NNTP-Posting-Host: starbase.spd.louisville.edu
  10. X-Newsreader: NN version 6.5.0 CURRENT #16
  11.  
  12. natewild@mbnet.mb.ca (Nathan T. Wild) writes:
  13.  
  14. >I am implimenting a system, but which executable code modules are loaded
  15. >from disk files into allocated blocks.
  16.  
  17. >This is working very well.  I allocated a big enough block, load the
  18. >"driver" in and aim a function pointer ar it.  
  19.  
  20. >What I would like to do is have the code that I load in contain near
  21. >pointers to it's own groups of functions.  I have placed a header on the
  22. >driver module I wish to load that contains the offset from the current
  23. >segment for two functions contained within the driver block.
  24.  
  25. >This time I want to calculate the segment and read in the offset and set
  26. >both function pointers accordingly.
  27.  
  28. >I am having difficulty dereferencing things???
  29.  
  30.  
  31.  
  32. >Say, for example that my code block is allocated at XXXX:0004.  The first 2
  33. >bytes are the pointer (within the block) to the first function and the next
  34. >2 bytes are the pointer to the second function.
  35.  
  36. >I want to set my function pointer to the segment XXXX and the offset stored
  37. >at XXXX:0004 & 0005.  No matter how I reference this, I get my function
  38. >pointing to XXXX:0004!
  39.  
  40.  
  41. >I have tried (where driverPtr == XXXX:0004 and is a void far *):
  42. >    func1ptr = (void far **)driverPtr
  43. >    func2ptr = (void far **)(driverPtr+2)
  44. >    
  45. >But I get XXXX:0004 every time?  I can set the function pointers to what I
  46. >want if I use MK_FP(), FP_SEG() and peek(), but there has got to be a
  47. >better way than this?
  48.  
  49. I would use MK_FP (it uses compiler primitives that manage segments and offsets)
  50. , but you might get away with:
  51.  
  52. func1ptr = (void far *)(*(short *)driverPtr);
  53. func2ptr = (void far *)(*(short *)(driverPtr+2));
  54.  
  55. Of course that last +2 may not work because driverPtr is void far *,
  56. so you may have to do something like:
  57.  
  58. func2ptr = (void far *)(*(((short *)driverPtr)+1));
  59.  
  60. And maybe unsigned shorts would be smarter, I don't know.
  61. And this still doesn't handle segments appropriately.  Oh well...
  62.  
  63.  
  64.  
  65. >In short, how, given the address of a stored pointer, set a function to
  66. >point to the address stored, no to the location it is stored in???
  67.  
  68. >This is driving me nuts as I am sure it is fairly simple...
  69.  
  70. >Please respond via Email, I cannot access this group "live"...
  71.  
  72. >Thanks in advance...
  73.  
  74. >|--------------------------------------------------------------------|
  75. >| ooooO (``)   (``) Ooooo | Nathan T. Wild                           | 
  76. >| (   ) )  (   )  ( (   ) | natewild@mbnet.mb.ca                     |
  77. >| )  (  (   ) (   ) )  (  | ftp://ftp.mbnet.mb.ca/pub/natewild       |
  78. >| (__)  ooooO Ooooo (__)  | http://www.mbnet.mb.ca/~natewild         |
  79. >|--------------------------------------------------------------------|
  80.